﻿var data = {};
var article = {};
var systemInfo = {}; //系统信息
article.id = getParams("id");
article.content = "";
article.addDate = "";
article.title = "";
article.authorName = "";
article.views = "";
systemInfo.netName = "博客";
systemInfo.adminName = "wkiny";
systemInfo.adminInfo = "java程序员";
systemInfo.whereFrom = "福建 漳州";
systemInfo.adminImg = "";
var sameArticles = [];
var hotArticles = [];
var leftMessages = [];
var tags = [];

data.leftMessages = leftMessages;
data.article = article;
data.sameArticles = sameArticles;
data.hotArticles = hotArticles;
data.systemInfo = systemInfo;
data.tags = tags;
var appVue = new Vue({
	el: "#app",
	data: data,
	methods: {
		articleDetail: function(id) {
			location.href = "detail.html?id=" + id;
		},
		searchByTag: function(tag) {
			location.href = "article.html?tag=" + tag;
		},
		submitLeftMessage: function() {
			//提交留言
			var content = $.trim(layui.layedit.getText(remarkEditor));
			if(content == "") {
				layui.layer.msg("请输入留言");
				return;
			}
			content = layui.layedit.getContent(remarkEditor);
			addLeftMessage(function(result) {
				layui.layer.msg("提交成功");
				leftMessages.unshift(result.data);
			}, article.id, content);
		}
	}
});
var remarkEditor = layui.layedit.build('remarkEditor', {
	height: 150,
	tool: ['face', '|', 'left', 'center', 'right', '|', 'link'],
});

$(function() {
	prettyPrint();
	//获取网站信息
	getSizeInfo(function(result) {
		var resultData = result.data;
		systemInfo.netName = resultData.siteShortTitle;
		systemInfo.adminName = resultData.adminRealname;
		systemInfo.adminInfo = resultData.adminProfession;
		systemInfo.whereFrom = resultData.adminPosition;
		systemInfo.adminImg = resultData.adminImg;
		document.title = resultData.siteTitle;
	});
	//获取文章信息
	getArticleDetail(function(result) {
		data.article = result.data;

		//获取相似文章
		getArticlePage(function(result) {
			var resultData = result.data;
			for(var i = 0; i < resultData.length; i++) {
				sameArticles.push(resultData[i]);
			};
		}, 1, 5, data.article.tags);
	}, article.id);
	//加载热门文章
	getArticlePage(function(result) {
		var resultData = result.data;
		for(var i = 0; i < resultData.length; i++) {
			hotArticles.push(resultData[i]);
		};
	}, 1, 5, null, 1);

	//获取热门分类
	getArticleTagPage(function(result) {
		var resultData = result.data;
		for(var i = 0; i < resultData.length; i++) {
			tags.push(resultData[i]);
		};
	}, 1, 6);
	//获取留言
	layui.flow.load({
		elem: '#div_article_leftmessage_buttom',
		isAuto: false,
		done: function(page, next) {
			getArticleLeftMessagePage(function(result) {
				var resultData = result.data;
				for(var i = 0; i < resultData.length; i++) {
					leftMessages.push(resultData[i]);
				};
				next("", page < result.totalPage);
			}, page, 5, article.id);
		}
	});

});